/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:58 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class ThongbaoDAL : SqlProvider<ThongbaoEntity>
    {
        static ThongbaoDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                ThongbaoEntity entity = new ThongbaoEntity();
				entity.PK_iThongbaoID = Int64.Parse("0"+dr["PK_iThongbaoID"].ToString());
                entity.FK_iNguoidangthongbaoID = Int64.Parse("0" + dr["FK_iNguoidangthongbaoID"].ToString());
                entity.dNgaydang = DateTime.Parse(dr["dNgaydang"].ToString());
                entity.sTieude = dr["sTieude"].ToString();
                entity.sNoidung = dr["sNoidung"].ToString();
                entity.iTrangthai = short.Parse(dr["iTrangthai"].ToString());
                return entity;
            };
        }
        public static ThongbaoEntity GetOne(Int64 PK_iThongbaoID)
        {
            string cmdName = "spThongbao_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iThongbaoID", PK_iThongbaoID);
            ThongbaoEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<ThongbaoEntity> GetAll()
        {
            string cmdName = "spThongbao_Get";
            return GetList(cmdName);
        }
        public static int Add(ThongbaoEntity entity)
        {
            string cmdName = "spThongbao_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(ThongbaoEntity entity)
        {
            string cmdName = "spThongbao_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iThongbaoID)
        {
            string cmdName = "spThongbao_Delete";
            SqlParameter p = new SqlParameter("@PK_iThongbaoID", PK_iThongbaoID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(ThongbaoEntity entity)
        {
            SqlParameter[] p = new SqlParameter[6];
			p[0] = new SqlParameter("@PK_iThongbaoID", entity.PK_iThongbaoID);
			p[1] = new SqlParameter("@FK_iNguoidangthongbaoID", entity.FK_iNguoidangthongbaoID);
			p[2] = new SqlParameter("@dNgaydang", entity.dNgaydang);
			p[3] = new SqlParameter("@sTieude", entity.sTieude);
			p[4] = new SqlParameter("@sNoidung", entity.sNoidung);
			p[5] = new SqlParameter("@iTrangthai", entity.iTrangthai);
            return p;
        }
        #endregion
       
    }
}